package com.champ.demo.controller;

import com.champ.demo.dto.UserDto;
import com.champ.demo.entity.User;
import com.champ.demo.repository.UserJpaRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping(value = "/api/users")
public class UserController {
    @Autowired
    UserJpaRepository repository;
    @PostMapping("/register")
    public User add(@RequestBody UserDto user) {
        return repository.save(new User(user.getName()));
    }
}
